<template>
	<view class="nameTable">
		<view  v-if="!auditShow">
			<other></other>
		</view>
		<view class="card">
			<view class="text">
				号码测算
			</view>
			<view class="card_box">
				
		<view class="" v-if="auditShow">
			<view class="nameTable_box">
				<view class="flex_row_start_center nameTable_item">
					<view class="nameTable_item_left">出生日期</view>
					 <input v-model="celenderValue" @click="showCalendar=true" disabled="true" placeholder-class="placeholder-class" placeholder="请选择日期" />
					<e-run-calendar ref="betterCalendarRef" :showCalendar="showCalendar" @confirm="selectDate" :isHourShow="true"
					        @cancel="showCalendar = false" :selectOptions="selectOptionsArr"></e-run-calendar>
				<uni-icons style="margin-left: 20rpx;" @click="openlistfn" type="list" size="16"></uni-icons>
				</view>
			</view>
			</view>
			<!-- 测算类型，手机号、车牌号 -->
			<view class="catages_box">
				<uni-data-checkbox v-model="value" :localdata="range" @change="change"></uni-data-checkbox>
			</view>
			<view class="nameTable_box" v-if="value==1">
				<view class="flex_row_start_center nameTable_item">
					<view class="nameTable_item_left">手机号码</view>
					<input @blur="blurfn" @input="inputfn" type="number" v-model="form.masterPhone" placeholder-class="placeholder-class" placeholder="请输入您的手机号" />
				     <view class="" style="color: #cecece; ">
				     	<span v-if="phonetype==1">中国移动</span>
						<span v-if="phonetype==2">中国联通</span>
						<span v-if="phonetype==3">中国电信</span>
				     </view>
				</view>
			</view>
			<view class="nameTable_box" v-if="value==2">
				<view class="flex_row_start_center nameTable_item">
					<view class="nameTable_item_left">车牌号码</view>
					 <car-number-input style="width: 70%;" @numberInputResult="numberInputResult" :defaultStr="defaultNum"></car-number-input>
					<!-- <input v-model="form.name" placeholder-class="placeholder-class" placeholder="请输入您的车牌号码" /> -->
				</view>
			</view>
			<view class="nameTable_button"@click="numberinfo">确认</view>
			<uni-popup ref="popup" type="center" border-radius="30px 30px 30px 30px">
				<view class="list" style="width: 600rpx;height: 600rpx;">
					<view class="list_title">
						档案库
					</view>
					<view class="" style="overflow-y: scroll; max-height: 450rpx;">
						<view class="item" v-for="(item,index) in danganlist" :key="index">
							<view @click="selectfn(item)" class="item_c" style="display: flex;align-items: center;width: 100%;">
								<uni-icons color="#bb9435" type="circle" size="14"></uni-icons>
								<view class="" style="margin-left: 20rpx; ">
									<view class="name">
										{{item.masterName}}
									</view>
									<view class="date">
										{{item.masterBirthday}}
									</view>
								</view>
							</view>
							
						</view>
					</view>
					
				</view>
			</uni-popup>
		</view>
		</view>
	</view>
</template>

<script>
	import eRunCalendar from "@/uni_modules/e-run-calendar/components/e-run-calendar/e-run-calendar.vue"
	import other from '@/components/other/index.vue'
	export default{
		components:{other,eRunCalendar},
		data(){
			return{
				// 车牌接键盘
				  defaultNum: '赣A',
				  
				
				value: 1,
				range: [{"value": 1,"text": "手机号"	},{"value": 2,"text": "车牌号"},],
				auditShow:false,
				
				showCalendar: false,//是否显示组件
				celenderValue: '',//选择值
				selectOptionsArr: [80, 0, 0, 0],///起始年份
				form:{
					masterPhone:'',
					// gender:'男',
					year: null, 
					month:null, 
					day: null, 
					hour: null, 
					minute: null, 
					isLeap: null, 
					numberType:1,
					 payType:'BALANCE',
					 payMethod:'balance',
					 amount:0,//金额
					 productId:8,
					 productName:'号码测算',
					 productCover:null,
					 productType:'',
					 productPrice:null,
					masterInfoId:null,//个人档案id
					masterName:null,
					code:'',
					codeSource:'',
					bankCode:'',
					bankAccount:'',
					
				},
				celenderValue:'',
				danganlist:[],//档案库数据
				isphone:false,//手机号是否正确
				phonetype:0,//1 移动 2 联通 3 电信
			}
		},
		onLoad(){
			this.getreportlist()
		},
		onShow(){
			this.getAudit()
			
		},
		methods:{
			// 跳转pages/moreModule/ordertest/ordertest
			numberinfo(){
				 // 要传递的对象参数
				 if(!this.form.masterPhone){
				 	if(this.value==1){
				 		this.$modal.msg('请输入手机号码！')
				 	}else if(this.value==2){
				 		this.$modal.msg('请输入车牌号码！')
				 	}
				 	return false 
				 }else if(!this.form.year){
				 	this.$modal.msg('请选择时间！')
				 	return false 
				 }else if(this.form.masterPhone && this.value==1){
				 	if(!this.isphone){
				 		this.$modal.msg('请输入正确的手机号码！')
				 		return false 
				 		 
				 	}
				 	
				 }
				uni.navigateTo({
					url:"/pages/moreModule/ordertest/ordertest?numberobj="+encodeURIComponent(JSON.stringify(this.form))
				})
			},
			// 获取推荐报告列表
			getreportlist(){
				this.$request({
					url:'v3/business/front/product/list',
					method:'GET',
					data:{
						productId:this.form.productId,
					},
				}).then(res=>{
					if(res.state==200){
						this.form.productId=res.data.list[0].productId
						this.form.productName=res.data.list[0].productName
						this.form.productType=res.data.list[0].productType
						this.form.salesCount=res.data.list[0].salesCount
						this.form.productDetail=res.data.list[0].productDetail
						this.form.productPrice=res.data.list[0].productPrice
						this.form.productCover=res.data.list[0].productCover
					}
				})
			},
			// 选择信息
			openlistfn(){
				this.$refs.popup.open()
				this.getdanganlist()
			},
			// 获取档案数据
			getdanganlist(){
				 
				this.$request({
					url:'v3/member/front/master/list',
				}).then(res=>{
					if(res.state==200){
						this.danganlist=res.data
					}
				})
			},
			// 选择档案
			selectfn(val){
				this.$refs.popup.close()
				console.log(val);
				this.celenderValue=val.masterBirthday
				this.form.isLeap=val.isLeap
				this.form.year=val.masterBirthday.split(' ')[0].split('/')[0]
				this.form.month=val.masterBirthday.split(' ')[0].split('/')[1]
				this.form.day=val.masterBirthday.split(' ')[0].split('/')[2]
				this.form.hour=val.masterBirthday.split(' ')[1].split(':')[0]
				this.form.minute=val.masterBirthday.split(' ')[1].split(':')[1]
				this.form.dateType=val.isLeap=='true' || val.isLeap=="false"?'1':'0'
				this.form.leapMonth=val.isLeap=='true'?true:false
				// this.form.phone=val.masterPhone
				this.form.masterInfoId=val.masterInfoId
				this.form.masterName=val.masterName
				console.log(val,this.form);
				 
			},
			
			// 手机号校验
			blurfn(e){
				var regex = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
			   this.isphone=regex.test(e.detail.value)
			   if(!this.isphone){
				   this.$modal.msg('请输入正确的手机号！')
			   }
			   
			},
			inputfn(e){
				 
				// 检测运营商
				      const isChinaMobile =/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|178|18[2-478])\d{8}$/; // 移动
				      const isChinaUnion = /^(?:13[0-2]|145|15[56]|176|18[56])\d{8}$/; // 联通
				      const isChinaTelcom = /^(?:133|153|177|18[019])\d{8}$/; // 电信
				if(isChinaMobile.test(e.detail.value)){
								   this.phonetype=1
				}else if(isChinaUnion.test(e.detail.value)){
								   this.phonetype=2
				}else if(isChinaTelcom.test(e.detail.value)){
								   this.phonetype=3
				}
			},
			// 手机号码、车牌号码
			change(e){
				this.value=e.detail.value
				if(this.value==1){
					this.form.productId=8
				}else if(this.value==2){
					this.form.productId=9
				}
				this.form.numberType=this.value
				this.form.masterPhone=null
			},
			// 车牌输入
			numberInputResult(e) {
			            console.log('结果--' + e)
						this.form.masterPhone=e
			        },
			
			
			//获取微信审核开关
			getAudit(){
			    let param = {};
				param.url='v3/system/front/configuration/1'
				this.$request(param).then(res=>{
					console.log(res);
					this.auditShow=res.data.auditSwitch
					if(this.auditShow){
						uni.setNavigationBarTitle({
							title:'号码数理'
						})
					}
				})
			},
			changeSex(sex){
				this.form.gender=sex==0 ? '男':'女';
			},
			selectDate(e){
				console.log('e',e);
				if(e.type == 'solar'){
					//公历
					this.currentIndex=0
					this.form.isLeap=null
					this.form.year=e.year
					this.form.month=e.month
					this.form.day=e.day
					this.form.hour=(e.hour+1).toString().padStart(2, '0')
					this.form.minute="00"
					this.celenderValue=e.year+'/'+e.month+'/'+e.day+'/'+' '+(e.hour+1).toString().padStart(2, '0')+":"+'00'
				}else if(e.type == 'lunar'){
					//农历
					this.currentIndex=1
					this.celenderValue=e.year+'/'+e.month+'/'+e.day+'/'+' '+(e.hour+1).toString().padStart(2, '0')+":"+'00'
					//判断是否闰月
					this.form.year=e.year
					this.form.month=e.month
					this.form.day=e.day
					this.form.hour=(e.hour+1).toString().padStart(2, '0')
					this.form.minute="00"
					this.form.isLeap= e.leap_month == 1 ? 'true':'false'
				
				}
				console.log('this.form.masterBirthday',this.form.masterBirthday);
				this.showCalendar=false
			},
			natTo(url,item){
				// 要传递的对象参数
				if(!this.form.name){
					if(this.value==1){
						this.$modal.msg('请输入手机号码！')
					}else if(this.value==2){
						this.$modal.msg('请输入车牌号码！')
					}
					return false 
				}else if(!this.form.year){
					this.$modal.msg('请选择时间！')
					return false 
				}else if(this.form.masterPhone && this.value==1){
					if(!this.isphone){
						this.$modal.msg('请输入正确的手机号码！')
						return false 
						 
					}
					
				}
				const obj = this.form
				// console.log('obj',obj);
				
				// 将对象参数转为JSON字符串，并使用encodeURIComponent编码
				const params = encodeURIComponent(JSON.stringify(obj));
				
				// 跳转页面并传递对象参数
				uni.navigateTo({
				   url: `${url}?params=${params}`
				});
			},
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #f0eff4;
	}
	// 弹出狂样式
	.list{
		padding: 28rpx;
		border-radius: 20rpx;
		// text-align: center;
		background-color: #fff;
		.list_title{
			font-size: 30rpx;
			font-weight: 550;
			color: #88b7ff;
			margin-bottom: 20rpx;
			padding-bottom: 10rpx;
			border-bottom: 2rpx solid #cecece;
			text-align: center;
		}
		.item{
			padding: 10rpx 20rpx;
			font-size: 26rpx;
			border-bottom: 2rpx solid #cecece;
			display: flex;
			align-items: center;
			.name{
				font-size: 28;
				padding: 10rpx 0;
				font-weight: 550;
			}
			.date{
				color: #cecece;
			}
		}
		
	}
	.card{
		background-color: #88b7ff;
		height: 500rpx;
		padding: 40rpx 30rpx;
		position: relative;
		.text{
					  padding-top: 50rpx;
					  font-size: 80rpx;
					  font-weight: 550;
					  width: 100%;
					  text-align: center;
					  color: #f9fefc;
		}
		.card_box{
			 position: absolute;
			 top: 250rpx;
			 left: 40rpx;
			 right: 40rpx;
		}
	}
	.nameTable{
		// padding: 50rpx 60rpx;
	}
	.catages_box,.nameTable_box{
		background-color: #fff;
		padding: 30rpx 20rpx;
	}
	.nameTable_item{
		padding: 10rpx 10rpx;
		font-size: 28rpx;
	    border-bottom: 2rpx solid #eeeeee;	
	}
	.nameTable_item_left{
		margin-right: 36rpx;
	}
	.nameTable_button{
		color: #fff;
		margin-top: 48rpx;
		border-radius: 15rpx;
		font-size: 36rpx;
		padding: 24rpx 0;
		text-align: center;
		background-color: #88b7ff;
		letter-spacing: 6rpx;
	}
	.addArchives_sex{
		width: 100rpx;
	}
</style>